

/****** Object:  StoredProcedure [dbo].[SP_recRole_GridPage]    Script Date: 05/10/2014 08:26:26 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



-- =============================================
-- Author:		Beni Khaeroni (jhung.ben@gmail.com)
-- Create date: 09 Mei 2014 01:19 PM
-- Description:	
-- =============================================
   CREATE PROCEDURE [dbo].[SP_recRole_GridPage]
    @startRow  [int]
   ,@endRow    [int]
   ,@param [varchar] (max)
   ,@sortName [varchar](50)
   ,@sortOrder [varchar](10)
   AS
   BEGIN
   DECLARE @SQL nvarchar(max);
   SET @SQL ='
    WITH result_set AS  (  
    SELECT       ROW_NUMBER() OVER (
    ORDER BY
       '+@sortName+' '+@sortOrder +'
    ) AS [row_number],
    RoleID, RoleName, CreatedBy, CreatedDate, UpdatedBy, UpdatedDate
    FROM  
        [master].recRole '
      if (@param  <> '')
      BEGIN
		SET @SQL = @SQL + @param
      END
      
      SET @SQL = @SQL +'
    ) 
    SELECT * FROM result_set WHERE [row_number] BETWEEN '+ Convert(varchar,@startRow) +' AND ' + Convert(varchar,@endRow) 
    exec sp_executesql @SQL
    print @SQL
 END
    
   


GO


